﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataObjects.Interface.Production;
using BusinessObjects.Production;
using DataObjects.AdoNet;

namespace DataObjects.SqlServer.Production
{
    public class SqlServerInventoryLedgerDao : IInventoryLedgerDao
    {
        public void InsertInventoryLedger(InventoryLedger inventoryLedger)
        {
            string sql = "Insert_InventoryLedger";

            inventoryLedger.InventoryLedgerID = Db.Insert(sql, true, Take(inventoryLedger));
        }

        public void DeleteInventoryLedgerByRefId(InventoryLedger inventoryLedger)
        {
            string sql = "Proc_Delete_InventoryLedger_ByRefID";

            object[] parms = {  "@RefID", inventoryLedger.RefID,
                                "@RefNo", inventoryLedger.RefNo};

            Db.Update(sql, true, parms);
        }

        private object[] Take(InventoryLedger inventoryLedger)
        {
            return new object[]  
            {
                "@InventoryLedgerID", inventoryLedger.InventoryLedgerID,
                "@RefID", inventoryLedger.RefID,
                "@RefType", inventoryLedger.RefType,
                "@RefDate", inventoryLedger.RefDate,
                "@PostedDate", inventoryLedger.PostedDate,
                "@RefNo", inventoryLedger.RefNo,
                "@RefDetailID", inventoryLedger.RefDetailID,
                "@StockID", inventoryLedger.StockID,
                "@InventoryItemID", inventoryLedger.InventoryItemID,
                "@RestaurantMenuID", inventoryLedger.RestaurantMenuID,
                "@Unit", inventoryLedger.Unit,
                "@UnitPrice", inventoryLedger.UnitPrice,
                "@InwardQuantity", inventoryLedger.InwardQuantity,
                "@OutwardQuantity", inventoryLedger.OutwardQuantity,
                "@InwardAmount", inventoryLedger.InwardAmount,
                "@OutwardAmount", inventoryLedger.OutwardAmount,
                "@JournalMemo", inventoryLedger.JournalMemo,
                "@Description", inventoryLedger.Description,
                "@OutwardPurpose", inventoryLedger.OutwardPurpose,
                "@RestaurantID", inventoryLedger.RestaurantID
            };
        }
    }
}